#ifndef __RENDER_PASS_H__
#define __RENDER_PASS_H__

#pragma once

#include "RenderStates.h"
#include "ShaderParameter.h"
#include "ShaderProgram.h"

 namespace Nezha
 {

	 /**  */
	 class GRAPHICS_ENTRY RenderPass
	 {
	 public:
		 RenderPass(const _string& name);
		 virtual ~RenderPass();

		 // must be called when render this pass
		 bool begin();
		 void end();

		 const _string& getName() const
		 {
			 return mName;
		 }

		 u32 getNumParams() const
		 {
			 return mShaderParams.size();		 
		 }

		 // set shader parameters
		 // REMARKS built-in parameters will not been modified.
		 void setShaderParamFloat(const _string& name, float f);

		 void setShaderParamVector(const _string& name, const Vector3& vec);

		 void setShaderParamVector(const _string& name, const Vector4& vec);

		 void setShaderParamMatrix(const _string& name, const Matrix3x3& mat);

		 void setShaderParamMatrix(const _string& name, const Matrix4x4& mat);

		 // TODO sampler

		ShaderParameter* getParam(u32 i);

		ShaderParameter* getParamByName(const _string& name);

		 u8 getNumSamplers() const
		 {
			 return (u8)mSamplers.size();
		 }

		 ShaderSampler* getSamper(u32 i);

		 const ShaderProgram* getProgram() const
		 {
			 return mProgram.ptr();
		 }

		 ShaderProgram* getProgram()
		 {
			 return mProgram.get();
		 }

		 const ShaderProgramPtr& getProgramPtr() const
		 {
			 return mProgram;
		 }

		 ShaderProgramPtr getProgramPtr()
		 {
			 return mProgram;
		 }

		 static u8 GetMaxSamplersPerPass()
		 {
			 return msMaxSamplersPerPass;
		 }

		 /** initialize with shader program.
		 @brief
			RenderPass will distill the parameter prototypes used by program,
			and construct them.
		 */
		 void setProgram(const ShaderProgramPtr& program);

		 void copyRenderStatesFrom(const RenderPass* pass);

NEZHA_INTERNAL:

		 RS_Blending mBlending;
		 RS_Depth mDepth;
		 RS_PolygonOffset mOffset;
		 RS_Stencil mStencil;
		 RS_CullOrder mCull;
		 RS_FillMode mFillMode;
		 RS_ColorMask mColorMask;

		// set by graphics driver object.
		static void _SetMaxSamplersPerPass(u8 num);

	 protected:
		 void destroyParams();

		 PArray<ShaderParameter*> mShaderParams;
		 ShaderProgramPtr mProgram;

		 typedef PArray<ShaderSampler*> SamplerList;
		 // REMARKS this is only the reference of the shader parameters.
		 SamplerList mSamplers;

		 //// reserved
		 //RRHandle mHandle;

		 _string mName;

		static u8 msMaxSamplersPerPass;
	 };

 }// end namespace Nezha


#endif //end __RENDER_PASS_H__